<!--分页查询共用的页面-->
<%@ include file="/common/paginateUtil.jsp"%>

<%@ include file="/common/dateUtil.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>

<style>
	select {
			width:80px;
	    }
		input [type="text"]
		{
			width:150px;
		}
	</style>
</head>

<script type="text/javascript" charset="utf-8">


	function getEndTimeColumn(value, rowData, rowIndex) {
		var endTime = rowData.endTime;
		var status = rowData.status;
		if (status == 'New')
			return '<span style="color:red;font-weight:bold;">报警中..</span>';
		return endTime;
	}
	//编辑列
	function getEditActionColumn(value, rowData, rowIndex) {
		var entityId = rowData.id;
		var sVal = rowData.processed; //处理标志位
		if (sVal != '未处理')
			return sVal;
		var html = "<a href=\"javascript:InfoWindow.viewAlarm('" + entityId + "');\">" + " 未处理</a>";
		return html;

	}

	function getAttachementListColumn(value, rowData, rowIndex) {
		if (value == null || value == 0)
			return "无";

		// var entityId = rowData.id;


		var entityId = rowData.id;
		var html = "<a href=\"javascript:InfoWindow.viewAdasAlarmAttachmentList('" + entityId + "');\">" + value + " </a>";
		return html;

	}

	function validateDate() {
		var startTime = $("#startTime").val();
		var endTime = $("#endTime").val();
		startTime = new Date(Date.parse(startTime.replace(/-/g, "/")));
		endTime = new Date(Date.parse(endTime.replace(/-/g, "/")));
		if (isNaN(startTime.getTime()) || isNaN(endTime.getTime())) {
			$.messager.alert('提示', '非法的日期格式');
		}
		var today = new Date();

		var date1 = new Date(startTime.getFullYear(), startTime.getMonth(), startTime.getDate());
		var date2 = new Date(endTime.getFullYear(), endTime.getMonth(), endTime.getDate());
		if (startTime > today) {
			$.messager.alert('提示', '开始日期不能大于当前日期');
			return false;
		}
		if (startTime >= endTime) {
			$.messager.alert('提示', '开始时间不能大于等于结束时间');
			return false;
		}

		var iMonth = endTime.getMonth() - startTime.getMonth();
		if (iMonth > 1 || (iMonth < 0 && iMonth != -11)) {
			$.messager.alert('提示', '一次只能查询不超过两个月的历史数据');
			return false;
		}
		return true;
	}

	function processAlarm() {
		//获取checkbox选中的行的区域Id
		var checkedItems = $('#queryGrid').datagrid('getChecked');
		var strAlarmId = [];
		$.each(checkedItems, function (index, item) {
			strAlarmId.push(item.id);
		});
		if (strAlarmId.length == 0) {
			$.messager.alert("提示", "请选择要处理的报警记录!");
			return;
		}

		var alarmIds = strAlarmId.join(",");
		var params = { strAlarmId: alarmIds };
		var url = "<%=ApplicationPath%>/alarm/batchProcess.action";

		$.getJSON(url, params, function (result) {
			$("#btnQuery").click();
			if (result.success) {
				$.messager.alert("提示", "命令已经下发,请稍后刷新状态!");
			}
			else
				$.messager.alert("提示", "提交失败! 错误原因：" + (result.message ? result.message : result.Data));
		});
	}

	$(document).ready(function () {

		var now = Utility.today();
		$("#endTime").val(now + " 23:59:00");
		var now = Utility.today();
		$("#startTime").val(now + " 00:00:00");
		//创建下拉部门树
		Utility.createDepTree("depId");
		$("#btnQuery").click(function () {
			if (validateDate()){
				Utility.loadGridWithParams();
				var queryForm = $("#queryForm").ajaxForm();
				 var formData = queryForm.formToArray();
				 console.log(formData);
			}
				
		});


		$("#processedWay").lookup({ category: "processType" });
		$("#alarmSource").lookup({ category: "AlarmSource" });

		$("#alarmType").lookup({ queryID: "selectAlarmTypeList" });
		//$("#alarmType").lookup({category:"alarmType"});//填充报警类型下拉框
		$("#alarmType").change(function () {
			var txt = $("#alarmType").find("option:selected").text();
			$("#alarmTypeName").val(txt);
		});
		$("#processedWay").change(function () {
			var txt = $("#processedWay").find("option:selected").text();
			$("#processedWayName").val(txt);
		});
		$("#processedState").change(function () {
			var txt = $("#processedState").find("option:selected").text();
			$("#processedStateName").val(txt);
		});
		$("#alarmSource").change(function () {
			var txt = $("#alarmSource").find("option:selected").text();
			$("#alarmSourceName").val(txt);
		});
		//双击事件
		$("#queryGrid").datagrid({
			onDblClickRow: function (rowIndex, rowData) {

				var alarmId = rowData.alarmId;
				var vehicleId = rowData.vehicleId;
				var plateNo = rowData.plateNo;
				var param = "?input=true&vehicleId="+vehicleId+"&alarmId="+alarmId;
				var url = "<%=ApplicationPath%>/alarmImage/viewAlarmImage.action"+param;
		  		var title = plateNo +"报警处理-查看";
				InfoWindow.open(url,  870, 570, title);
				console.log(title);
				console.log(alarmId);
			}
		});

	});
	$("#selectAll").change(
		function () {
			var checked = $(this).attr("checked");
			if (!checked)
				checked = false;
			$("input:checkbox[name='id']").attr("checked", checked);
		}
	);

</script>

<body>
	<div id="toolbar">

		<form id="queryForm" action="<%=ApplicationPath%>/report/paginate.action">
			<input type="hidden" name="queryId" value="adasAlarm.selectAdasAlarms" />
			<input type="hidden" name="fileName" value="报警信息" />
			<input type="hidden" id="alarmTypeName" name="alarmTypeName" value="所有" />
			<input type="hidden" id="processedWayName" name="processedWayName" value="所有" />
			<input type="hidden" id="processedStateName" name="processedStateName" value="所有" />
			<input type="hidden" id="alarmSourceName" name="alarmSourceName" value="所有" />
			<table width="100%" class="TableBlock">
				<tr>
					<td> 车牌号码 </td>
					<td>
						<input type="text" id="plateNo" name="plateNo">
					</td>
					<td> 车组名称 </td>
					<td>
						<select id="depId" name="depId" style="width:200px;"></select>
					</td>
					<td>报警类型</td>
					<td> <select id="alarmType" name="alarmType" width="10"></select></td>

					<td>报警来源</td>
					<td> <select id="alarmSource" name="alarmSource" width="10"></select>
					</td>

				</tr>
				<tr>

					<td align="right">开始时间
						:</td>
					<td>
						<input type="text" name="startTime" id="startTime" class="datetimepicker" />
					</td>
					<td>结束时间:</td>
					<td align="left">
						<input type="text" name="endTime" id="endTime" class="datetimepicker" />
					</td>
					<td colspan="4" align="left">
						<a id="btnQuery" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>&nbsp;
						<a id="btnReset" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-clear'">重置</a>&nbsp;
						<a id="btnExport" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-excel'" onclick="Utility.excelExport('<%=ApplicationPath%>/export.action');">导出</a>
						<!--调用utility.js-->
					</td>
				</tr>
			</table>
		</form>

	</div>
	<table id="queryGrid" class="easyui-datagrid" title="" style="width:100%;height:480px" data-options="pagination:true,pageSize:15,singleSelect:true,rownumbers:true,striped:true,fitColumns: true,checkOnSelect: false, selectOnCheck: false,
						pageList: [15, 20, 50, 100, 150, 200],fit:true,toolbar:'#toolbar',
						url:'<%=ApplicationPath%>/report/paginate.action',method:'get'">
		<thead>
			<tr>
				<th data-options="field:'id',checkbox:true" width="100"><input type='checkbox' id='selectAll'></input></th>
				<th data-options="field:'plateNo'" width="8%">车牌号</th>
				<th data-options="field:'plateColor'" width="5%">颜色</th>
				<th data-options="field:'depName'" width="10%">车组</th>
				<th data-options="field:'alarmType'" width="8%">报警类型</th>
				<th data-options="field:'alarmSource'" width="12%">报警来源</th>
				<th data-options="field:'level'" width="6%">报警级别</th>
				<th data-options="field:'alarmStatus'" width="6%">报警标志</th>
				<th data-options="field:'location'" width="20%">报警地点</th>
				<th data-options="field:'alarmTime'" width="12%">报警时间</th>
				<th data-options="field:'attachmentCount',formatter:getAttachementListColumn" width="6%">附件数</th>
				<th data-options="field:'speed'" width="6%">车速(km/h)</th>
				<th data-options="field:'frontCarSpeed'">前车车速</th>
				<th data-options="field:'frontCarDistance'">前车/行人距离</th>
				<th data-options="field:'deviateType'">偏离类型</th>
				<th data-options="field:'roadRecognitionMark'">道路标志识别类型</th>
				<th data-options="field:'roadRecognitionData'">道路标志识别数据</th>
				<th data-options="field:'fatigueDegree'">疲劳程度</th>
				<th data-options="field:'vehicleStatus'">车辆状态</th>
				<th data-options="field:'tirePressureAlarmDetail'">胎压报警内容</th>
				<th data-options="field:'longitude'">经度</th>
				<th data-options="field:'latitude'">纬度</th>
			</tr>
		</thead>
	</table>
</body>